package com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider;

import com.mallcai.bigdata.ladon.dpl.entity.peekdata.ModelMeta;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.ModelSchema;
import com.mallcai.bigdata.ladon.dpl.mapper.BaseSqlProvider;
import com.mallcai.bigdata.ladon.dpl.mapper.system.provider.UserSqlProvider;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-06-26 20:09
 */
public class ModelSchemaSqlProvider extends BaseSqlProvider<ModelSchema> {

    public static final String TB_MODEL_SCHEMA = "pd_model_schema";


    @Override
    public String getTableName() {
        return TB_MODEL_SCHEMA;
    }



    @Override
    public Map<String, String> getInsertColumns() {
        return null;
    }

    @Override
    public Map<String, String> getUpdateColumns() {
        return null;
    }

    /**
     * 根据参数查询
     */
    public String getByParams(Map<String, Object> map) {
        Map<String, Object> params = getParams(map);

        StringBuilder sb = new StringBuilder();
        sb.append("tb_m.archive = 0");
        if (params.containsKey("datasourceId") && params.get("datasourceId") != null) {
            sb.append(" and tb_m.datasource_id = #{params.datasourceId}");
        }
        if (params.containsKey("tableName") && StringUtils.isNotBlank(params.get("tableName").toString())) {
            sb.append(" and tb_m.table_name = #{params.tableName}");
        }
        return new SQL() {
            {
                SELECT("tb_m.*");
                FROM(TB_MODEL_SCHEMA + " tb_m");
                WHERE(sb.toString());
            }
        }.toString();
    }


}
